from db import db


class User(db.Model):
    """
    create table user
    (
        id         int auto_increment
            primary key,
        username   varchar(100)                         null,
        password   varchar(255)                         null,
        email      varchar(255)                         null,
        last_login datetime   default CURRENT_TIMESTAMP null,
        is_active  tinyint(1) default 1                 null,
        constraint email
            unique (email),
        constraint username
            unique (username)
    );
    """

    __tablename__ = "user"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(100), unique=True, nullable=True)
    password = db.Column(db.String(255), nullable=True)
    email = db.Column(db.String(255), unique=True, nullable=False)
    last_login = db.Column(db.DateTime, default=db.func.now())
    is_active = db.Column(db.Boolean, default=True)

    def __str__(self):
        return f"User(id={self.id}, username='{self.username}', email='{self.email}')"
